import 'package:flutter/material.dart';
import "package:get/get.dart";

import '../../../../common/my_icon.dart';
import '../../../../config/global_config.dart';
import '../../../../pages/Lift/lift_details/ctrl/lift_details_ctrl.dart';
import '../../../../utils/screenutil/fit.dart';

class RunTable extends StatelessWidget {
  // 导入控制器
  // final liftdetailsCtrl = Get.put(LiftDetailsCtrl());
//  final _ic = Get.put(InfoCtrl());
  final _ldc = Get.find<LiftDetailsCtrl>();

  double _top;

  RunTable({
    double top = 0,
  }) : this._top = top;

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => _ldc.latestAnalysis.value != null
          ? Container(
              width: 640.f,
              color: Colors.white,
              margin: EdgeInsets.only(top: _top),
              child: Column(
                children: [
                  Container(
                    width: 640.f,
                    padding: EdgeInsets.all(20.f),
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                          color: GlobalConfig.borderColor,
                        ),
                      ),
                    ),
                    child: Text(
                      "电梯运行统计",
                      style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 24.f),
                    ),
                  ),
                  createField(
                    "总开关门次数",
                    emptyValidation(
                      _ldc.latestAnalysis.value.doorOcTimes,
                      expect: '次',
                    ),
                  ),
                  createField(
                    "总故障次数",
                    emptyValidation(
                      _ldc.latestAnalysis.value.troubleTimes,
                      expect: '次',
                    ),
                  ),
                  createField(
                    "总困人次数",
                    emptyValidation(
                      _ldc.latestAnalysis.value.trapTimes,
                      expect: '次',
                    ),
                  ),
                  createField(
                    "总电动车进出次数",
                    emptyValidation(
                      _ldc.latestAnalysis.value.evTimes,
                      expect: '次',
                    ),
                  ),
                  createField(
                    "总里程数",
                    emptyValidation(
                      _ldc.latestAnalysis.value.totalMileage,
                      expect: 'km',
                    ),
                  ),
                  createField(
                      "总运行时长",
                      emptyValidation(
                        _ldc.latestAnalysis.value.totalRunTime,
                        expect: 'h',
                      ),
                      last: true),
                ],
              ),
            )
          : Container(
              width: 640.f,
              color: Colors.white,
              margin: EdgeInsets.only(top: _top),
              child: Column(
                children: [
                  Container(
                    width: 640.f,
                    padding: EdgeInsets.all(20.f),
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                          color: GlobalConfig.borderColor,
                        ),
                      ),
                    ),
                    child: Text(
                      "电梯运行统计",
                      style: TextStyle(
                          fontWeight: FontWeight.bold, fontSize: 24.f),
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 80.f),
                    color: Colors.white,
                    child: Column(
                      children: [
                        Icon(
                          MyIcon.empty,
                          color: GlobalConfig.assistColor,
                          size: 80.f,
                        ),
                        SizedBox(height: 10.f),
                        Text(
                          "查询不到电梯运行的数据",
                          style: TextStyle(
                            fontSize: 24.f,
                            color: GlobalConfig.assistColor,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
    );
  }

  Widget createField(String name, dynamic val, {bool last = false}) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Container(
            padding: EdgeInsets.symmetric(
              horizontal: 20.f,
              vertical: 25.f,
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  "$name",
                  style: TextStyle(
                    fontSize: 24.f,
                  ),
                ),
                Text(
                  "$val",
                  style: TextStyle(
                    fontSize: 24.f,
                    color: GlobalConfig.assistColor,
                  ),
                ),
              ],
            ),
          ),
          last
              ? SizedBox.shrink()
              : SizedBox(
                  height: 1,
                  width: 620.f,
                  child: Container(
                    color: GlobalConfig.borderColor,
                  ),
                )
        ],
      ),
    );
  }

  String emptyValidation(dynamic data, {String expect}) {
    if (data != null) {
      return "${data}/${expect}";
    }
  }
}
